package org.zsl.controller.springmvc;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zsl.model.ResponseMsg;
import org.zsl.model.User;
import org.zsl.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/user2")
public class RestfulController {

      @Autowired
      private UserService userService;

     @RequestMapping(value = "/get/{userId}",method = RequestMethod.GET)
     public User getUserById(@PathVariable("userId") Integer userId){
            return  userService.getSingle(userId);
     }


     @GetMapping("/list")
     public List<User> getUserById(){
         return  userService.getList();
     }


     @PostMapping("/add")
     public ResponseMsg add(User  user){
          return  userService.edit(user);
     }

     @PutMapping("/put")
     public  ResponseMsg edit(User user){
         return  userService.edit(user);
     }

     @DeleteMapping("/del/{userId}")
     public ResponseMsg remove(@PathVariable("userId") User userId){

         return  userService.del(userId);
     }
}
